const {
	Controller
} = require('uni-cloud-router');
module.exports = class UserController extends Controller {
	async login() {
		       const { ctx, service } = this;
			  
		       const post = Object.assign(ctx.data);
			   // 调用 service 进行业务处理
		return this.service.common.user.login(post)
	}

	async checkToken() {
			   // 调用 service 进行业务处理
		return this.service.common.user.checkToken()
	}
	async register() {
		       const { ctx, service } = this;
			 
		       const post = Object.assign(ctx.data);
			   // 调用 service 进行业务处理
		return this.service.common.user.register(post)
	}
	async logout() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const post = Object.assign(ctx.data);
			   // 调用 service 进行业务处理
		return this.service.common.user.logout(post)
	}
	async updatePwd() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const auth = await this.service.common.user.checkToken();
		       const uid = auth.uid;
		       const post = Object.assign(ctx.data, { uid });
			   // 调用 service 进行业务处理
		return this.service.common.user.updatePwd(post)
	}
	async resetPwd() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const auth = await this.service.common.user.checkToken();
		       const uid = auth.uid;
		       const post = Object.assign(ctx.data, { uid });
			   // 调用 service 进行业务处理
		return this.service.common.user.resetPwd(post)
	}
	async updateUser() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const auth = await this.service.common.user.checkToken();
		       const uid = auth.uid;
		       const post = Object.assign(ctx.data, { uid });
			   // 调用 service 进行业务处理
		return this.service.common.user.updateUser(post)
	}
	async bindRole() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const auth = await this.service.common.user.checkToken();
		       const uid = auth.uid;
		       const post = Object.assign(ctx.data, { uid });
			   // 调用 service 进行业务处理
		return this.service.common.user.bindRole(post)
	}
	async getUser() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const auth = await this.service.common.user.checkToken();
		       const uid = auth.uid;
		       const post = Object.assign(ctx.data, { uid });
			   // 调用 service 进行业务处理
		return this.service.common.user.getUser(post)
	}
	async getUserByRole() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const auth = await this.service.common.user.checkToken();
		       const uid = auth.uid;
		       const post = Object.assign(ctx.data, { uid });
			   // 调用 service 进行业务处理
		return this.service.common.user.getUserByRole(post)
	}
	//判断用户是否是超级管理员
	async isAdminByUser() {
		       const { ctx, service } = this;
			   //获取token需要异步才能获取
		       const auth = await this.service.common.user.checkToken();
		       const uid = auth.uid;
		       const post = Object.assign(ctx.data, { uid });
			   // 调用 service 进行业务处理
		return this.service.common.user.isAdminByUser(post)
	}
}
